package org.huawei260.OD260;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Auther: qingle
 * @Date: 2024/8/20-19:58
 * @Description:
 * @version: 1.0
 */
public class O0010_数据分类 {

		public static void main(String[] args) {
			// 示例输入数据，实际使用时需要根据实际情况提供
			Scanner scanner =new Scanner(System.in);
			int[] ints = new int[12];
			for (int i = 0; i < ints.length; i++) {
				ints[i] = scanner.nextInt();
			}
//			int[] inputData = {2, 3, 0x01010101, 0x01010103, ...}; // 填入剩余的10个数据
			List<String> classificationResults = classifyData(ints);

			// 打印分类结果
			for (String result : classificationResults) {
				System.out.println(result);
			}
		}

		public static List<String> classifyData(int[] data) {
			List<String> results = new ArrayList<>();
			int c = data[0];
			int b = data[1];

			for (int i = 2; i < data.length; i++) {
				int a = data[i];
				int sum = sumBytes(a);
				int moduloResult = sum % b;

				if (moduloResult < c) {
					results.add(String.valueOf(moduloResult)); // 有效类型
				} else {
					results.add("Invalid"); // 无效类型
				}
			}
			return results;
		}

		// 辅助方法，计算整数a的四个字节的和
		private static int sumBytes(int a) {
			return (a & 0xFF) + ((a >> 8) & 0xFF) + ((a >> 16) & 0xFF) + ((a >> 24) & 0xFF);
		}
	}